<?php
/**
 * Created by PhpStorm.
 * User: 73640
 * Date: 2018/10/31
 * Time: 11:25
 */

namespace App\Admin\Extensions\Export;
use App\Http\Controllers\Admin\Business\Repository\Combo;
use Encore\Admin\Grid\Exporters\AbstractExporter;
use Illuminate\Support\Carbon;
use Maatwebsite\Excel\Facades\Excel;

class ExchangeExport extends  AbstractExporter
{
        public function export()
        {
           $combo= Combo::pluck('title','id')->toArray();

            Excel::create('激活码'.Carbon::now(), function($excel)use($combo) {

                $excel->sheet('Sheetname', function($sheet)use($combo) {
                    $rows1=collect([['id','套餐','激活码','时间']]);
                    $rows = collect($this->getData())->map(function ($item)use($combo) {
                        return [
                            $item['id'],
                            $combo[$item['combo_id']] ?? '',
                            $item['code'],
                            $item['created_at'],
                        ];
                    });
                    $sheet->rows($rows1);
                    $sheet->rows($rows);
                });

            })->export('xls');
        }
}